home *** CD-ROM | disk | FTP | other *** search
- /*
- FileList 1.4
- "Init.c"
- */
-
- #include "Main.h"
- #include "Window.h"
- #include "File.h"
- #include "Options.h"
- #include "Stack.h"
- #include "Search.h"
- #include "Utilities.h"
- #include "Init.h"
- #include <FontMgr.h>
-
- /* ----- Init the Mac -------------------------------------------------- */
-
- static void InitMac (void)
- {
- register short i;
- pascal void Crash (void);
-
- for (i = 0; i < 5; i++)
- MoreMasters();
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(Crash);
- FlushEvents(everyEvent, 0);
- }
-
- /* ----- Init the menus ------------------------------------------------ */
-
- static void SetupMenus (void)
- {
- AppleM = GetMenu(AppleMenu);
- AddResMenu(AppleM, 'DRVR');
- InsertMenu(AppleM, 0);
- InsertMenu(FileM = GetMenu(FileMenu), 0);
- InsertMenu(EditM = GetMenu(EditMenu), 0);
- InsertMenu(VolumeM = GetMenu(VolumeMenu), 0);
- InsertMenu(FileData.sortmenu = GetMenu(FSortMenu), 0);
- InsertMenu(VolumeData.sortmenu = GetMenu(VSortMenu), 0);
- CheckItem(VolumeM, vAuto, Automatic);
- DrawMenuBar();
- }
-
- /* ----- Find volume reference number ---------------------------------- */
-
- static short ParentVolume (
- register short volume) /* Use 0 for default volume */
- {
- HVolumeParam p;
-
- p.ioCompletion = 0;
- p.ioVolIndex = 0;
- p.ioNamePtr = 0;
- p.ioVRefNum = volume;
- if ((!volume && PBGetVol(&p, FALSE)) || PBHGetVInfo(&p, FALSE))
- ExitToShell();
- return p.ioVRefNum;
- }
-
- /* ----- Check system environment -------------------------------------- */
-
- #define WNETrapNum 0x60 /* Trap number of WaitNextEvent() */
- #define UnImplTrapNum 0x9F /* Trap number "unimplemented trap" */
-
- static void CheckSystem (void)
- {
- SysEnvRec theWorld;
-
- Bounds = screenBits.bounds;
- if (SysEnvirons(1, &theWorld) || theWorld.machineType < 0) {
- Bounds.top += 20;
- Message(ERR_OLD, 0);
- ExitToShell();
- }
- SysVol = ParentVolume(SysVRefNum = theWorld.sysVRefNum);
- ApplVol = ParentVolume(0);
- Bounds.top += MBarHeight;
- WNE = NGetTrapAddress(WNETrapNum, ToolTrap) !=
- NGetTrapAddress(UnImplTrapNum, ToolTrap);
- }
-
- /* ----- Open new list ------------------------------------------------- */
-
- #define FONT_NUMBER monaco
- #define FONT_SIZE 9
-
- static void NewList (register WindowDataPtr p)
- {
- FontInfo info;
- Rect r;
-
- p->count = p->sorted = p->vrefnum = p->type = p->creator = 0;
- p->find[0] = 0;
- p->match = StrBegins;
-
- NewWindow(p, &p->rectangle, EmptyStr, FALSE, 8, -1L, TRUE, 0L);
- SetPort(p);
- TextFont(FONT_NUMBER);
- TextSize(FONT_SIZE);
- GetFontInfo(&info);
- /* info.widMax = CharWidth('M'); */ /* info.widMax not always correct */
- p->descent = info.descent;
- p->height = info.ascent + info.descent + info.leading;
- p->width = info.widMax;
-
- WPortRect(p->height, p->width, &p->rectangle);
- r = p->rectangle;
- SizeWindow(p, r.right - r.left, r.bottom - r.top, TRUE);
- WPortRect(p->height, p->width,
- &((WStateData *)*((WindowPeek)p)->dataHandle)->stdState);
-
- VScrollRect((WindowPtr)p, &r);
- p->vs = NewControl(p,&r,EmptyStr,TRUE,0,0,0,scrollBarProc,0L);
- HScrollRect((WindowPtr)p, &r);
- p->hs = NewControl(p,&r,EmptyStr,TRUE,0,0,0,scrollBarProc,0L);
-
- NewTitle(p);
- ShowWindow(p);
- }
-
- /* ----- Check application parameters ---------------------------------- */
-
- static void CheckApplParms (void)
- {
- register short i;
- short message, count;
- AppFile file;
-
- CountAppFiles(&message, &count);
- if (!count)
- return;
- for (i = 1; i <= count; i++){
- GetAppFiles (i, &file);
- if (file.fType != Creator)
- continue;
- Read(file.vRefNum, file.fName);
- Update();
- if (FileData.sorted)
- CheckItem(FileData.sortmenu, FileData.sorted, TRUE);
- if (VolumeData.sorted)
- CheckItem(VolumeData.sortmenu, VolumeData.sorted, TRUE);
- return;
- }
- }
-
- /* ----- Get parameters ------------------------------------------------ */
-
- static void GetParm (void)
- {
- register short err;
- register StringHandle str;
- short r;
- long count;
- Parameter parm;
- Rect bounds;
-
- err = 1;
- if (str = GetString(OPTION_FILE)) {
- HLock(str);
- err = FSOpen(*str, SysVRefNum, &r);
- HUnlock(str);
- if (!err) {
- count = sizeof(Parameter);
- err = FSRead(r, &count, &parm);
- FSClose(r);
- if (count != sizeof(Parameter) || parm.version != VERSION)
- err = 1;
- }
- }
- if (err) {
- parm.heap = 0x8000L;
- parm.volumes = 3; /* 3 % of records are volumes */
- parm.files = 86; /* 86 % of records are files */
- parm.name = 12; /* Average name size is 12 bytes */
- parm.date = 0;
- parm.automatic = 0;
- parm.stuffit = 0;
- parm.compactor = 0;
- parm.tabs = 0;
- bounds = Bounds;
- bounds.top += 20;
- parm.vwindow = bounds;
- parm.fwindow = bounds;
- }
- if (NewMemory(parm.heap, parm.files, parm.volumes, parm.name)) {
- Message(ERR_MEMORY, 0);
- ExitToShell();
- }
- VolumeData.rectangle = parm.vwindow;
- FileData.rectangle = parm.fwindow;
- DFormat1(parm.date);
- Automatic = parm.automatic;
- Tabs = parm.tabs;
- Stuffit = parm.stuffit;
- Compactor = parm.compactor;
- }
-
- /* ----- Initializations ----------------------------------------------- */
-
- void Init (void)
- {
- void FileToString1(), FileToString2();
- void SortFiles();
- void VolumeToString1(), VolumeToString2();
- void SortVolumes();
-
- InitMac();
- CheckSystem();
- GetParm();
- SetupMenus();
-
- notQuiting = TRUE;
- BlockMove(*GetString(CREATOR) + 1, &Creator, 4L);
- BlockMove(*GetString(OPTIONS) + 1, &Options, 4L);
- BlockMove(*GetString(TEXT_CREATOR) + 1, &TextCreator, 4L);
- VolumeData.redraw = VolumeToString1;
- FileData.redraw = FileToString1;
- if (Tabs) {
- VolumeData.string = VolumeToString2;
- FileData.string = FileToString2;
- } else {
- VolumeData.string = VolumeToString1;
- FileData.string = FileToString1;
- }
- VolumeData.sort = SortVolumes;
- FileData.sort = SortFiles;
- VolumeData.title = TITLE_VOLUMES;
- FileData.title = TITLE_FILES;
- VolumeData.header = HEADER_VOLUMES;
- FileData.header = HEADER_FILES;
- VolumeData.maxsort = VSORT_MAX;
- FileData.maxsort = FSORT_MAX;
- VolumeData.columns = 90;
- FileData.columns = 255;
- VolumeData.select = FileData.select = -1L;
- InfoCount = InfoSize = 0L;
- Dirty = FALSE;
- VrefNum = 0;
-
- NewList(&VolumeData);
- NewList(&FileData);
-
- CheckApplParms();
- InitCursor();
- }
-